package com.ctsi.flowable.engine.service;

import com.ctsi.commons.util.UtilValidate;
import com.ctsi.flowable.idm.dto.GroupDTO;
import com.ctsi.flowable.idm.dto.GroupQuery;
import com.ctsi.flowable.idm.dto.UserQuery;
import com.ctsi.framework.mybatis.support.MybatisGenericDao;
import com.ctsi.organise.common.model.Person;
import com.ctsi.organise.entity.PersonEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author: zhangjw
 * @Date: 2018/11/19 10:06
 * @Description:
 */
@Repository
public class FlowableService {

    @Autowired
    private MybatisGenericDao dao;

    public List<GroupDTO> getPartys(GroupQuery groupQuery) {
        return (List<GroupDTO>) dao.queryForList(GroupDTO.class.getName()+".findGroupDTO",groupQuery);
    }

    public long getPartysCount(GroupQuery groupQuery) {
        return (Long) dao.queryForObject(GroupDTO.class.getName()+".findGroupDTO_count",groupQuery);
    }

    public long findUserCountByQueryCriteria(UserQuery query) {
        return (Long) dao.queryForObject(GroupDTO.class.getName()+".findUserByQueryCriteria_count",query);
    }

    /**
     * @param query
     * @return
     */
    public List<Person> findUserByQueryCriteria(UserQuery query) {
        return (List<Person>) dao.queryForObject(GroupDTO.class.getName()+".findUserByQueryCriteria",query);
    }

    /**
     * 根据ID查找 UserEntity对象
     */
    public Person findUserByPartyId(String partyId) {
        if (UtilValidate.isEmpty(partyId)) {
            return null;
        }
        return dao.get(PersonEntity.class, partyId);
    }

}
